﻿using System.Collections.Generic;

namespace Theoreme.Teaching.AOP.Sample01
{
    public class UserRoleList 
    {
        private readonly Dictionary<User, List<string>> dictionary = new Dictionary<User, List<string>>();

        public void AddRole( User user, string role )
        {
            List<string> list;
            if ( !this.dictionary.TryGetValue( user, out list ) )
            {
                list = new List<string>();
                this.dictionary.Add( user, list );
            }

            list.Add( role );
        }

        public bool ContainsUserRole( User user, string role )
        {
            List<string> list;
            if ( !this.dictionary.TryGetValue( user, out list ) )
            {
                return false;
            }

            return list.Contains( role );
        }
    }
}